package com.test.blogsystem.Comment.Advice;

import com.test.blogsystem.Comment.Exception.BlogException;
import com.test.blogsystem.Pojo.Response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@ControllerAdvice
@ResponseBody
@Slf4j
public class ExceptionActive {
    @ExceptionHandler
    public Result exceptionHandler(Exception exception){
        log.error("发生异常, e: {}", exception);
        return Result.fail(exception.getMessage());
    }

    @ExceptionHandler
    public Result exceptionHandler(BlogException exception){
        log.error("发生异常, e: {}", exception);
        return Result.fail(exception.getMessage());
    }

    @ExceptionHandler
    public Result exceptionHandler(NoResourceFoundException exception){
        log.error("发生异常：{}",exception);
        return Result.fail(exception.getMessage());
    }
}
